﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KaoWuYou.Models;
using System.IO;
using KaoWuYouLibs.Bll;

namespace KaoWuYou.Controllers
{
    [HandleError]
    public class AdministratorController : Controller
    {
        //
        // GET: /Administrator/
        //

        TestPaperManagementBusiness testPaperManagementBusiness = new TestPaperManagementBusiness();

        public ActionResult TestPaperImport()
        {
            return View();
            throw new NotImplementedException();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult TestPaperImport(TestPaperImportModel model)
        {
            foreach (string file in Request.Files)
            {
                string filePath = AppDomain.CurrentDomain.BaseDirectory + "UploadedFiles/";
                string fileName = "[" + DateTime.Now.ToString("yy-MM-dd_hh-mm-ss") + "]" + Path.GetFileName(Request.Files[file].FileName);
                string fullPath = Path.Combine(filePath, fileName);
                Request.Files[file].SaveAs(fullPath);

                testPaperManagementBusiness.ImportTestPaper(fullPath);
            }
            //todo
            //throw new NotImplementedException();

            return View();
        }

        [AcceptVerbs(HttpVerbs.Get)]
        public ActionResult DeleteTestPaper()
        {
            DeleteTestPaperModel model = new DeleteTestPaperModel();
            model.TestPapers = new List<KaoWuYouLibs.Model.TestPaperModel>();
            model.TestPapers.Add(new KaoWuYouLibs.Model.TestPaperModel() { TestPaperName = "111", TestPaperID = 1 });
            model.TestPapers.Add(new KaoWuYouLibs.Model.TestPaperModel() { TestPaperName = "222", TestPaperID = 2 });
            model.TestPapers.Add(new KaoWuYouLibs.Model.TestPaperModel() { TestPaperName = "333", TestPaperID = 3 });
            model.TestPapers.Add(new KaoWuYouLibs.Model.TestPaperModel() { TestPaperName = "444", TestPaperID = 4 });
            model.TestPapers.Add(new KaoWuYouLibs.Model.TestPaperModel() { TestPaperName = "555", TestPaperID = 5 });
            return View(model);
            throw new NotImplementedException();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult DeleteTestPaper(FormCollection forms, DeleteTestPaperModel model)
        {
            return View(model);
            throw new NotImplementedException();
        }

        public ActionResult UpdateTestPaper()
        {
            return View();
            throw new NotImplementedException();
        }

        public ActionResult QuestionImport()
        {
            return View();
            throw new NotImplementedException();
        }

        // **************************************
        // URL: /Administrator/QuestionQuery
        // **************************************

        public ActionResult QuestionQuery()
        {
            QuestionQueryModel model = new QuestionQueryModel();
            model.Subclasses = new List<KaoWuYouLibs.Model.SubclassModel>();
            model.Subclasses.Add(new KaoWuYouLibs.Model.SubclassModel() { SubclassID = 1, SubclassName = "Xs is a sx." });
            model.Subclasses.Add(new KaoWuYouLibs.Model.SubclassModel() { SubclassID = 2, SubclassName = "Xs is a xs." });
            model.Subjects = new SelectList(model.Subclasses, "SubclassID", "SubclassName");
            return View(model);
        }

        public ActionResult RecycleAccount()
        {
            return View();
            throw new NotImplementedException();
        }
    }
}
